<template>
  <view>
    <MajorSearchVue v-if="isMajorSearch" />
  </view>
</template>

<script>
import MajorSearchVue from "./MajorSearch.vue";
import ShareMixin from "@/mixins/share";
import { getShowPageType } from "@/api/modules/career.js";
import { addBuryingPoint } from "@/api/modules/career";
export default {
  mixins: [ShareMixin],
  name: "MajorSearchSub",
  data() {
    return {
      shareTitle: "查查你的专业的就业前景",
      isMajorSearch: true,
      personId: uni.getStorageSync("person-id").slice(2) || undefined,
      sharePath: `/pagesSub/careerNew/positionDictionary/MajorSearchSub?${this.shareQuery}`,
      shareQuery: `jumpPersonId=${this.personId}&jumpSource=10&sourceType=10`,
      shareCareerInfoParams: {},
      buryingPointId: "",
      cardType: "",
    };
  },
  created() {
    // this.checkPage();
  },
  onShow() {
    this.buryingPointId = "";
    //  埋点统计访问次数
    this.addBuryingPointFn(20070, "", "", "", "");

    // 埋点统计时长
    this.addBuryingPointFn(20071, "60", "", "", "");
  },
  onHide() {
    console.log("这里进入了onHide周期");
    this.addBuryingPointFn(20071, "60", "", "", "");
  },
  onUnload() {
    console.log("这里进入了onUnload周期");
    this.addBuryingPointFn(20071, "60", "", "", "");
  },
  onLoad(opt) {
    let jumpPersonId = "";
    if (opt.jumpPersonId) {
      jumpPersonId = opt.jumpPersonId;
    }
    let jumpSource = "";
    if (opt.jumpSource) {
      jumpSource = opt.jumpSource;
    }
    let sourceType = "";
    if (opt.sourceType) {
      sourceType = opt.sourceType;
    }

    this.sharePath = `/pagesSub/careerNew/positionDictionary/MajorSearchSub?${this.shareQuery}`;
    this.shareQuery = `jumpPersonId=${this.personId}&jumpSource=10&sourceType=10`;

    this.shareCareerInfoParams = {
      etId: 20072,
      id: this.buryingPointId ? this.buryingPointId : "", //后台要求不能传空，未登录也要统计
      personId: uni.getStorageSync("person-id").slice(2) || "0",
      cardType: this.cardType ? this.cardType : uni.getStorageSync("cardType") || this.cardType,
      consultantId: uni.getStorageSync("sellId")
        ? uni.getStorageSync("sellId")
        : "",
      originType: this.originFrom == "shareLink" ? 10 : 20,
      statType: "40",
      jumpPersonId: jumpPersonId,
      jumpSource: jumpSource,
      sourceType: sourceType,
    };
    console.log(
      "----this.shareCareerInfoParams--------->",
      this.shareCareerInfoParams
    );
    //外部链接点击统计事件
    if (jumpSource && sourceType) {
      this.addBuryingPointFn(20086, "50", jumpPersonId, jumpSource, sourceType);
    }
  },
  methods: {
    //普通的埋点+事件停留埋点
    async addBuryingPointFn(
      etId,
      statType,
      jumpPersonId,
      jumpSource,
      sourceType
    ) {
      const params = {
        etId: etId,
        id: this.buryingPointId ? this.buryingPointId : "", //后台要求不能传空，未登录也要统计
        personId: uni.getStorageSync("person-id").slice(2) || "0",
        cardType: this.cardType
          ? this.cardType
          : uni.getStorageSync("cardType") || this.cardType,
        consultantId: uni.getStorageSync("sellId")
          ? uni.getStorageSync("sellId")
          : "",
        originType: this.originFrom == "shareLink" ? 10 : 20,
        statType: statType ? statType : "10",
        jumpPersonId: jumpPersonId,
        jumpSource: jumpSource,
        sourceType: sourceType,
      };
      const res = await addBuryingPoint(params);
      if (res.code == 200) {
        if (res.data.id) {
          if (etId == 20071) this.buryingPointId = res.data.id;
        }
      }
    },
    checkPage() {
      uni.showLoading();
      //要加一个空参数不然webservice会调用失败
      getShowPageType({ params: 123 })
        .then((res) => {
          if (res.data.pageType == 1) {
            //查专业
            this.isMajorSearch = true;
          } else {
            //查职业
            // uni.switchTab({
            //   url: "/pages/career/positionDictionary/allCategory",
            // });
            uni.navigateTo({
              url: `/pagesSub/careerGrow/allCategory/allCategory`,
            });
          }
        })
        .finally(() => {
          uni.hideLoading();
        });
    },
  },
  components: {
    MajorSearchVue,
  },
};
</script>

<style lang="scss" scoped></style>
